package operation;

import book.List.bookList;
import book.List.book ;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-08
 * TIME:19:23
 */
public class addoperation implements IOoperation {

    @Override
    public void work(bookList bookList) {
        System.out.println("新增图书！");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名：");
        String name = scanner.nextLine();

        System.out.println("请输入作者：");
        String author = scanner.nextLine();

        System.out.println("请输入类型：");
        String where = scanner.nextLine();

        System.out.println("请输入价格：");
        int price = scanner.nextInt();

        book books = new book(name,author,where,price);

        //检查 数组当中 有没有这本书
        int currentSize = bookList.getUsesize();
        for (int i = 0; i < currentSize; i++) {
            book book1 = bookList.getBook(i);
            if(book1.getName().equals(name)) {
                System.out.println("有这本书，不进行存放了！");
                return;
            }
        }
        if(currentSize == bookList.getBooks().length) {
            System.out.println("书架满了！");
        }else {
            bookList.setBooks(currentSize,books);
            System.out.println(bookList .getBook(currentSize) );
            bookList .setUsesize(currentSize+1);
            System.out.println(bookList .getUsesize() );


        }
    }

    }

